local skel = fk.CreateSkill {
  name = "lb__fengci",
}

Fk:loadTranslationTable {
  ["lb__fengci"] = "蜂刺",
  --[":lb__fengci"] = "“<b>衣匠</b>”的回合开始时，你可以使用一张【铁索连环】或对其距离1以内的角色使用一张【杀】，若如此做，移除此“<b>衣匠</b>”，然后你从弃牌堆中获得另一张牌。",
  --9.7
  --[":lb__fengci"] = "“<b>衣匠</b>”的回合开始时，你可以使用一张【铁索连环】或对其距离1以内的角色使用一张【杀】，若如此做，移除此“<b>衣匠</b>”，然后你摸一张牌并从弃牌堆中获得另一张牌。",
  --9.18
  [":lb__fengci"] = "“<b>衣匠</b>”的回合开始时，你可以使用一张【铁索连环】或对其距离1以内的角色使用一张【杀】，若如此做，移除此“<b>衣匠</b>”，然后你摸一张牌并获得一张弃牌堆中与另一种牌名相同的牌，若没有则改为摸两张牌。",

  ["#lb__fengci"] = "蜂刺：你可以使用一张【铁索连环】或对 %dest 距离1以内的角色使用一张【杀】",
  ["#lb__fengci-chain"] = "蜂刺：你可以使用一张【铁索连环】",
  ["#lb__fengci-slash"] = "蜂刺：你可以对 %dest 距离1以内的角色使用一张【杀】",

  ["$lb__fengci1"] = "谎言啊，纤毫毕现。",
  ["$lb__fengci2"] = "生命啊，脆若游丝。",
}

skel:addEffect(fk.TurnStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and (target.general == "lb__yijiang" or target.deputyGeneral == "lb__yijiang")
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local name = room:askToChoice(player, {
      choices = { "slash", "iron_chain", "Cancel" },
      skill_name = skel.name,
      prompt = "#lb__fengci::" .. target.id,
    })
    if name ~= "Cancel" then
      local use_data = { ---@type AskToUseCardParams
        pattern = name,
        skill_name = skel.name,
        cancelable = true,
        prompt = "#lb__fengci-chain",
        extra_data = {},
      }
      if name == "slash" then
        local tos = table.filter(room:getOtherPlayers(target), function(to)
          return target:distanceTo(to) <= 1
        end)
        table.insert(tos, target)
        use_data.extra_data.exclusive_targets = table.map(tos, Util.IdMapper)
        use_data.extra_data.bypass_distances = true
        use_data.prompt = "#lb__fengci-slash::" .. target.id
      end
      local use = room:askToUseCard(player, use_data)
      if use then
        event:setCostData(self, { use = use, name = name })
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:useCard(event:getCostData(self).use)
    if target.general == "lb__yijiang" or target.deputyGeneral == "lb__yijiang" then
      room:changeHero(target, "", false, target.deputyGeneral == "lb__yijiang", true, false)
    end
    local name = (event:getCostData(self).name ~= "slash") and "slash" or "iron_chain"
    local ids = room:getCardsFromPileByRule(name, 1, "discardPile")
    if #ids > 0 then
      player:drawCards(1, skel.name)
      room:obtainCard(player, ids, true, fk.ReasonJustMove, nil, skel.name)
    else
      player:drawCards(2, skel.name)
    end
  end,
})

return skel
